<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../lib/vue.js"></script>
    <style>
      input {
        width: 30px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="input-num">
      <button @click="add">+</button>
      <span><input type="text" v-model="num" /></span>
      <button @click="reduce">-</button>
    </div>
    <script>
      let vu = new Vue({
        el: '.input-num',
        data: {
          num: 1,
        },
        methods: {
          add: function () {
            if (this.num < 100) {
              this.num++
            } else {
              alert('您输入的数字过大')
            }
          },
          reduce: function () {
            if (this.num > 1) {
              this.num--
            } else {
              alert('请不要输入0')
            }
          },
        },
      })
    </script>
  </body>
</html>
